package com.iqiju.guagua.photo.wx.mini.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 接口返回通用封装
 */
@ApiModel("通用接口返回对象")
public class Results<T> {
    /** 成功code */
    public static final int SUCCESS_CODE = 0;

    /** 参数错误 state */
    private static final int PARAM_ERROR_CODE = 100;

    /** 未知错误 state */
    private static final int UNKNOWN_ERROR_CODE = 500;


    /** 成功 message */
    public static final String SUCCESS_MSG = "SUCCESS";
    /** 位置错误 message */
    private static final String UNKNOWN_ERROR = "UNKNOWN_ERROR";



    @ApiModelProperty(required = true,notes = "结果码",example = "0")
    private int state;
    @ApiModelProperty(required = true,notes = "时间戳",example = "1567425139000")
    private long time;
    @ApiModelProperty(required = true,notes = "返回信息",example = "SUCCESS")
    private String message;
    @ApiModelProperty(required = true,notes = "返回数据")
    private T content;

    public Results() {}


    public Results(int state, String message, T content) {
        this.state = state;
        this.message = message;
        this.content = content;
        this.time = System.currentTimeMillis();
    }

    /** 默认成功结果 */
    public static Results success(){
        Results results = new Results();
        results.setState(SUCCESS_CODE);
        results.setMessage(SUCCESS_MSG);
        results.setTime(System.currentTimeMillis());
        return results;
    }

    /** 默认成功结果 */
    public static Results success(Object content){
        Results results = new Results();
        results.setState(SUCCESS_CODE);
        results.setMessage(SUCCESS_MSG);
        results.setContent(content);
        results.setTime(System.currentTimeMillis());
        return results;
    }

    /** 默认未知错误结果 */
    public static Results error() {
        Results results = new Results();
        results.setState(UNKNOWN_ERROR_CODE);
        results.setMessage(UNKNOWN_ERROR);
        results.time = System.currentTimeMillis();
        return results;
    }

    /** 未知错误结果  自定义消息 */
    public static Results error(String message) {
        Results results = new Results();
        results.setState(UNKNOWN_ERROR_CODE);
        results.setMessage(message);
        results.time = System.currentTimeMillis();
        return results;
    }


    /** 参数错误结果 */
    public static Results paramError(String msg) {
        Results results = new Results();
        results.setState(PARAM_ERROR_CODE);
        results.setMessage(msg);
        results.time = System.currentTimeMillis();
        return results;
    }







    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }
}
